package com.wjjun.test.ui

import android.view.View
import androidx.databinding.ViewDataBinding
import com.wjjun.base.ui.activity.BaseLazyActivity
import com.wjjun.app.R
import com.wjjun.test.ui.viewmodel.TestStatusViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.delay
import kotlinx.coroutines.withTimeoutOrNull
import java.util.*

/**
 *
 * author : wangjunjun
 * date   : 2022/6/28
 * desc   :
 */
@AndroidEntryPoint
class TestStatusActivity : BaseLazyActivity<TestStatusViewModel, ViewDataBinding>() {

    override fun initContent() {
        setTitle("测试多状态界面")
        setErrorPage(0, "错误界面")
        setEmptyPage(0, "空界面")
        setPermissionPage(0, "授权界面")
    }

    override fun initLazyContent(viewDataBinding: ViewDataBinding) {

    }

    override fun initParams() {
    }


    override suspend fun fetchData() {
        statusViewHelper.showLoading()
        delay(1000)
        finishLoad()
    }

    override fun onClick(view: View) {
        when (view.id) {
            R.id.tv_show_loading -> {
                initData()
            }
            R.id.tv_show_empty -> {
                statusViewHelper.showEmpty()
            }
            R.id.tv_show_error -> {
                statusViewHelper.showError()
            }
            R.id.tv_show_permission -> {
                statusViewHelper.showPermissionError()
            }
        }
    }

}